Insertion requires traversal to the predecessor node, resulting in $O(n)$ complexity.
- While traversal allows us to efficiently read all $n$ elements, modification operations like insertion require similar $O(n)$ time complexity because we must first **traverse** to the target location.
- Insertion requires finding the node immediately preceding the target position $i$, which is position $i-1$.
- We use a pointer $p$ to iterate to the node at index $i-1$. This traversal dictates the overall $O(n)$ time complexity.
- After creating the new node ($tmp$), the insertion requires two critical pointer assignments to "splice" the new node into the chain.
- **Relink 1 (New to Successor):** The `next` pointer of $tmp$ must point to the successor of $p$ (`p.next`).
- **Relink 2 (Predecessor to New):** The `next` pointer of $p$ (`p.next`) must be updated to point to the new node ($tmp$).
Complexity Summary: Insertion at Position $i$
| Operation | Time Complexity | Space Complexity |
|---|---|---|
| Insertion at $i$ | $O(n)$ | $O(1)$ |
The $O(n)$ time is dominated by the mandatory traversal to find the predecessor node at index $i-1$.